import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

fig, ax = plt.subplots()

x = np.arange(0, 2 * np.pi, 0.01)
line, = ax.plot(x, np.sin(x))


# 产生动画
def func(i):
    line.set_ydata(np.sin(x + i / 10))
    return line,


def init_func():
    line.set_ydata(np.sin(x))
    return line,


ani = animation.FuncAnimation(fig=fig, func=func,
                              frames=100,  # 动画帧
                              init_func=init_func,
                              interval=20,  # 跟新间隔
                              blit=False)  # 全局跟新

plt.show()
